<%--
  Created by IntelliJ IDEA.
  User: 肖
  Date: 2020/10/3
  Time: 21:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<br>
<div class="row" style="margin-top: 10px;">
    <div class="col-md-6">
        <button id="kanjias" type="button" class="btn btn-primary btn-sm">
            <span class="glyphicon glyphicon-refresh"></span>刷新
        </button>
        <button id="more_del_btn_kanjia"  type="button" class="btn btn-danger btn-sm">
            <span class=" glyphicon glyphicon-trash"></span>批量删除
        </button>

    </div>
    <div class="col-md-6" style="float: right;">
        <form class="bs-example bs-example-form" role="form">
            <div class="row">
                <div class="input-group input-group-sm col-md-6" style="margin: 0 auto;">
                    <input type="text" id="kanjiasearch" class="form-control" placeholder="请输入" value="${search}">
                    <span class="input-group-btn">
                                    <button id="kanjiabutton" class="btn btn-default btn-primary" type="button">
                                        <span class="glyphicon glyphicon-search"></span>&nbsp搜索
                                </button>
                                </span>
                </div>
            </div>
        </form>
    </div>
</div>
                    <div class="tab-pane fade in active" >
                        <table class="table table-hover table-responsive">

                            <thead>
                            <tr>
                                <th><input id="ck_all_kanjia" type="checkbox"></th>
                                <th>买家</th>
                                <th>电话</th>
                                <th>出价</th>
                                <th>底价</th>
                                <th>标价</th>
                                <th>车辆编号</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <c:forEach items="${page.list}" var="p" varStatus="vs">
                            <tr>
                                <th><input value="${p.id}" name="ck_content_kanjia" type="checkbox"></th>
                                <td >${p.uname}</td>
                                <td >${p.uphone}</td>
                                <td >${p.caPrice}</td>
                                <td >${p.caBaseprice}</td>
                                <td >${p.caSellprice}</td>
                                <td >${p.cId}</td>

                                    <td>
                                        <a onclick='del(this,${p.id})' class="text-danger" href="#"><span class="glyphicon glyphicon-trash"></span></a>
<%--                                        <a class="text-warning" href="#"><span class="glyphicon glyphicon-edit"></span></a>--%>
                                    </td>
</tr>
<%--                                </tr>--%>
                            </c:forEach>

                            </tbody>
                        </table>
                    </div>
<script>



    //批量删除start
    $(function(){
        let ck = document.getElementById("ck_all_kanjia");
        let cks = document.getElementsByName("ck_content_kanjia");
        ck.onclick=function(){
            if(ck.checked){
                for(let i=0;i<cks.length;i++){
                    cks[i].checked=true;
                }
            }else{
                for(let i=0;i<cks.length;i++){
                    cks[i].checked=false;
                }
            }
        }
    });
    $(function(){
        document.getElementById("more_del_btn_kanjia").onclick=function(){
            let cks = document.getElementsByName("ck_content_kanjia");
            let count = 0;
            for(let i=0;i<cks.length;i++){
                if(cks[i].checked){
                    count++;
                }
            }
            if(count==0){
                alert("sorry,请你先选中!");
                return;
            }
            let flag = confirm("确定删除吗?");
            if(flag){
                let sids = "";
                for(let i=0;i<cks.length;i++){
                    if(cks[i].checked){
                        sids+=cks[i].value+":";
                    }
                }
                $.post('/prj/seller/delallkanjia.action',{"sid":sids},function(data){
                    if(data.code=="200"){
                        $("#kanjia").load("/prj/seller/kanjia.action",{id:selid});
                    }
                })

            }
        };
    });


//异步刷新

    $("#kanjias").click(function () {

        $("#kanjia").load("/prj/seller/kanjia.action",{id:selid});
    })

    $("#kanjiabutton").click(function () {
        let search = $("#kanjiasearch").val();

        $("#kanjia").load("/prj/seller/kanjia.action",{id:selid,search:search});
    })
    function del(obj,id){

        $.post('/prj/seller/kanjiadel.action',{"id":id},function(data){
            if(data.code=="200"){
                let tr = obj.parentElement.parentElement;
                $(tr).remove();
            }
        })
    }
</script>
<%@include file="../page/kanjiaPage.jsp" %>